package com.fairylove.rpc.serializer;

public interface CommonSerializer {

    Integer KROY_SERIALIZER = 0;
    Integer JSON_SERIALIZER = 1;
    Integer HESSIAN_SERIALIZER = 2;
    Integer PROTOBUF_SERIALIZER = 3;
    Integer  DEFAULT_SERIALIZER = KROY_SERIALIZER;
    static CommonSerializer getByCode(int code){
         switch (code){
             case 0:
                 return new KryoSerializer();
             case 1:
                 return new JsonSerializer();
             case 2:
                 return new HessianSerializer();
             case 3:
                 return new ProtobufSerializer();
             default:
                 return null;
         }
    }
    /**
     * 序列化
     * @param obj
     * @return
     */
    byte[] serialize(Object obj);

    /**
     * 反序列化
     * @param bytes
     * @param clazz
     * @param <>
     * @return
     */
    Object deserialize(byte[] bytes,Class<?> clazz);

    int getCode();

}
